home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cbibcode.arc / MULTFUNC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-05  |  2.2 KB  |  117 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4.  
  5. /* Define a table of function names and numbers */
  6.  
  7.  
  8. #define CNTRL 0
  9. #define DIGIT 1
  10. #define GRAPH 2
  11. #define LOWER 3
  12. #define PRINT 4
  13. #define PUNCT 5
  14. #define SPACE 6
  15. #define UPPER 7
  16. #define XDIGIT 8
  17.  
  18. typedef struct FUNC_TABLE
  19. {
  20.     char name[16];
  21.     int funcnum;
  22. }FUNC_TABLE;
  23.  
  24. /* Now declare the table and initialize it */
  25. static FUNC_TABLE isfuncs[9] =
  26. {
  27.     "iscntrl", CNTRL, "isdigit", DIGIT,
  28.     "isgraph", GRAPH, "islower", LOWER,
  29.     "isprint", PRINT, "ispunct", PUNCT,
  30.     "isspace", SPACE, "isupper", UPPER,
  31.     "isxdigit" , XDIGIT
  32. };
  33. static int numfunc = sizeof(isfuncs)/sizeof(FUNC_TABLE);
  34. main(int argc, char **argv)
  35. {
  36.     int ch, count, i, test_result,
  37.         mark = 0xdb;                        /* to mark characters */
  38.     if (argc < 2)
  39.     {
  40.         printf("Usage: %s <function_name>\n", argv[0]);
  41.         exit(0);
  42.     }
  43.  
  44. /* Search table for function name and pointer */
  45.  
  46.     for(i=0; i<numfunc; i++)
  47.     {
  48.         if (strcmp(argv[1], isfuncs[i].name) == 0)
  49.             break;
  50.     }
  51.     if (i >= numfunc)
  52.     {
  53.         printf("Unknown function: %s\n", argv[1]);
  54.         exit(0);
  55.     }
  56.  
  57. /* Now go over entire ascii table and mark the
  58.  * characters that satisfy requested test.
  59.  */
  60.  
  61.     printf(
  62.     "Those marked with a %c satisfy %s\n",
  63.             mark, argv[1]);
  64.     for(count = 0, ch = 0; ch <= 0x7f; ch++)
  65.     {
  66.         printf("%#02x ", ch);
  67.  
  68.  /* Print character -- if printable            */
  69.  
  70.         if(isprint(ch))
  71.         {
  72.             printf(" %c", ch);
  73.         }
  74.         else
  75.         {
  76.             printf("  ");
  77.         }
  78.  
  79.  /* Perform the test and put a mark if test succeeds */
  80.  
  81.         switch(isfuncs[i].funcnum)
  82.         {
  83.             case CNTRL: test_result = iscntrl(ch);
  84.                         break;
  85.             case DIGIT: test_result = isdigit(ch);
  86.                         break;
  87.             case GRAPH: test_result = isgraph(ch);
  88.                         break;
  89.             case LOWER: test_result = islower(ch);
  90.                         break;
  91.             case PRINT: test_result = isprint(ch);
  92.                         break;
  93.             case PUNCT: test_result = ispunct(ch);
  94.                         break;
  95.             case SPACE: test_result = isspace(ch);
  96.                         break;
  97.             case UPPER: test_result = isupper(ch);
  98.                         break;
  99.             case XDIGIT:test_result = isxdigit(ch);
  100.                         break;
  101.         }
  102.         if(test_result != 0)
  103.         {
  104.             printf("%c ", mark);
  105.         }
  106.         else
  107.         {
  108.             printf("  ",ch);
  109.         }
  110.         count++;
  111.         if(count == 8)
  112.         {
  113.             printf(" \n");
  114.             count = 0;
  115.         }
  116.     }
  117. }